

class MainScene extends egret.DisplayObjectContainer {
	public constructor() {
		super();
		this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
	}


	private bgScene:BgScene; // 滚动背景

	private roleScene:RoleScene; // 角色场景

	private sound:egret.Sound;
	private soundChannel:egret.SoundChannel;


	private onAddToStage(et: egret.Event) {
		this.removeEventListener(egret.Event.ADDED, this.onAddToStage, this);

		// 滚动背景
		this.bgScene = new BgScene();
		this.addChild(this.bgScene);

		// 角色场景
		this.roleScene = new RoleScene();
		this.addChild(this.roleScene);
		this.roleScene.addEventListener("GameOver", this.stopGame, this);

		
		// 暂停按钮
		// this.pauseBtn = new egret.Bitmap();
        // this.pauseBtn.texture = RES.getRes("");
        // this.addChild(this.pauseBtn);
        // this.pauseBtn.touchEnabled = true;
        // this.pauseBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onPauseButtonTouch, this);

		//
		this.sound = RES.getRes("music_mp3");
		this.soundChannel = this.sound.play(0, 0);
		
		this.startGame();
	}

	// 点击暂停按钮
	private onPauseButtonTouch(et:egret.TouchEvent) {
		this.pauseGame();
	}

	// 开始游戏
	public startGame() {
		SettingManager.shareManger().gameState = 1;
		this.bgScene.startScroll();
		this.roleScene.roleSceneStart();
	}

	// 暂停游戏 
	public pauseGame() {
		SettingManager.shareManger().gameState = 2;
		this.bgScene.stopScroll();
	}

	// 结束游戏
	public stopGame(et:egret.Event) {
		SettingManager.shareManger().gameState = 0;
		this.bgScene.stopScroll();
		this.roleScene.roleSceneStop();

		this.soundChannel.stop();
	}

}